// 会员管理 王宇辰
<template>
  <div id="container">
    <Topnav />
    <Search @searchParent="searchfun" @searchdate="searchdate" />
    <Maincom :viparr="viparr" @resetparentfun="getData" />
    <Pages :total="total" :pageSize="pageSize" />
    <!-- 弹框组件 -->
    <Dialog />
  </div>
</template>

<script>
import Maincom from "./components/Maincom.vue";
import Pages from "./components/Pages.vue";
import Search from "./components/Search.vue";
import Topnav from "./components/Topnav.vue";
import Dialog from "./components/Dialog.vue";
import { getVIP, searchDate } from "../../api/VIP";
export default {
  components: { Search, Maincom, Pages, Topnav, Dialog },
  mounted() {
    this.getData(); //首屏函数执行
  },
  data() {
    return {
      viparr: [],
      search: "",
      page: 1,
      pageSize: 10,
      total: 0,
      wholeLength: 0,
      searchdate1: "",
      searchdate2: "",
    };
  },
  methods: {
    getData() {
      const params = {
        search: this.search,
        page: this.page, //页码
        pageSize: this.pageSize, //每页多少条
      };
      getVIP(params).then((res) => {
        console.log(res);
        if (res.code == 200) {
          this.viparr = res.data;
          this.total = res.total;
          this.wholeLength = res.length;
        }
      });
    },
    searchfun(val) {
      console.log(val);
      this.search = val;
      if (this.search != "") {
        this.getData1();
      } else {
        this.getData();
      }
    },
    getData1() {
      const params = {
        search: this.search,
        page: this.page, //页码
        pageSize: this.pageSize, //每页多少条
      };
      getVIP(params).then((res) => {
        console.log(res);
        if (res.code == 200) {
          this.viparr = res.data1;
          this.total = res.total;
          this.wholeLength = res.length;
        }
      });
    },
    searchdate(val) {
      const params = {
        sdate1: JSON.stringify(val[0]).substr(1, 10).split("-").join(""),
        sdate2: JSON.stringify(val[1]).substr(1, 10).split("-").join(""),
      };
      searchDate(params).then((res) => {
        console.log(res);
        if (res.code == 200) {
          this.viparr = res.data3;
          this.total = res.total;
        }
      });
    },
  },
};
</script>

<style>
#container {
  background-color: white;
  padding-top: 14px;
  padding-left: 20px;
}
</style>
